/********************************************************************************
 * Copyright(c) 2020-2025 BST All rights reserved.
 * - Filename
 * - Author
 * - Version V1.0.0
 * - Date    2024/08/28
 * - Brief
 * - FunctionList:
 ******************************************************************************
 * History:
 *
 *
 *
 ******************************************************************************
 */
#pragma once

#include "Lidar.hpp"
#include "GetLidarData_LS.h"
#include "TimeUtil.h"
#include <condition_variable>
#include <deque>
#include <mutex>

namespace lslidar {

class LsLidar128s2Adapter : public lidar::Lidar {
public:
  LsLidar128s2Adapter(const uint32_t &id, const std::string &ip,const uint16_t &msop_port,
                 const uint16_t &difop_port);
  ~LsLidar128s2Adapter();
  void start(
      std::function<void(std::shared_ptr<lpc::LidarProtoPointCloud> &&)>) override;
  void stop() override;

protected:
  const uint32_t _id;
  const uint32_t _ip;
  const uint16_t _msopPort;
  const uint16_t _difopPort;

private:
  bool _isExit{true};
  TimeUtil::FpsCalc _fps{};
  std::shared_ptr<GetLidarData_LS> _lidar{nullptr};
  std::shared_ptr<std::thread> _lidarFrameThread{nullptr};
  std::shared_ptr<std::thread> _getLidarFrameThread{nullptr};
  std::mutex _mtx;
  std::condition_variable _condition;
  std::deque<std::shared_ptr<lpc::LidarProtoPointCloud>> _lidarFrameDeque{};
  void
  processLoop(const std::function<void(std::shared_ptr<lpc::LidarProtoPointCloud> &&)>
                  &callback);

  void getLidarFrameLoop();
  void lidarFrameCallback(const std::shared_ptr<  std::vector<MuchLidarData>>data,int count,std::string info);
};
} // namespace lslidar